package ControlLayer;

import java.util.ArrayList;
import ModelLayer.*;

public class LoanCtr
{
    /**
     * Singleton constructor
     */
    private LoanContainer loanContainer;
    {
        loanContainer = LoanContainer.getInstanse();
    }
    
    /**
     * Creates a new loan
     */
    public void newLoan(Person person, Example example, String date, String period)
    {
       loanContainer.newLoan(person, example, date, period);
    }
    
    /**
     * updates a loan (ie changes "is-lend-out" -status)
     */
    public void updateLoan(Person person, Example example, String date, boolean isLendOut)
    {
        for(Loan loan :loanContainer.getAllLoans())
        {
            
            if(loan.getPerson().equals(person) && loan.getExample().equals(example) && loan.getDate().equals(date))
            {
                loan.updateStatus(isLendOut);
            }
        }
    }
    
    /**
     * Returns all loans
     */
    public ArrayList<Loan> getLoans()
    {
        return loanContainer.getAllLoans();
    }

}